import data
import pyglet
import pygletutil
from pyglet.window import key
from pyglet.gl import *

from game import *

class gameWindow(pyglet.window.Window):
	def __init__(self):
		super(gameWindow,self).__init__(width=data.assets.width,height=data.assets.height)
		
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
	
		self.label = pyglet.text.Label('Trash Heap Avenger')
		
		self.mode = 0
		self.introScreen = 0
		self.prefScreen = 1
		self.playingGame = 2

		self.keys = key.KeyStateHandler()
		self.push_handlers(self.keys)
		
		data.assets.loadImage("thruster1")
		data.assets.loadImage("thruster2")
		data.assets.loadImage("thruster4")
		data.assets.loadImage("title")
		
		self.game = RobotGame(self.keys)
		
		pyglet.clock.schedule(self.draw)
	def on_draw(self):
		pass #self.draw()
	def draw(self,dt):
		timer.update(dt)
		self.clear()
		if self.mode == self.introScreen:
			glClearColor(1.0,1.0,1.0,1.0)
			data.assets.images['title'].blit(assets.width/2,assets.height/2)
		elif self.mode == self.playingGame:
			self.game.draw()
	def on_key_press(self, symbol, modifiers):
		if self.mode == self.introScreen:
			if symbol == key.SPACE:
				self.mode = self.playingGame
				return
		if self.mode == self.playingGame:
			self.game.handleKeys(symbol, modifiers)
			return


def main():
	window = gameWindow()
	pyglet.app.run()
